<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<%@ include file="/WEB-INF/views/include/easyui.jsp"%>
</head>
<body style="font-family: '微软雅黑'">
	<div id="tb" style="padding: 5px; height: auto">
		<div>
			<form id="searchFrom" action="">
				<input type="text" name="filter_LIKES_tempname"
					class="easyui-validatebox" data-options="width:150,prompt: '模板名称'" />
				<select id="cc" class="easyui-combobox" name="filter_LIKES_status"
					data-options="width:150,panelHeight:100,prompt: '模板状态'" >
					<option></option>
					<option value="0">可用</option>
					<option value="1">禁用</option>
				</select> <span class="toolbar-item dialog-tool-separator"></span> <a
					href="javascript(0)" class="easyui-linkbutton" plain="true"
					iconCls="icon-search" onclick="cx()">查询</a>
			</form>
			<!--  -->
			<shiro:hasPermission name="lcs:marketTemplate:add">
				<a href="#" class="easyui-linkbutton" plain="true"
					iconCls="icon-add" onclick="add();">添加</a>
				<span class="toolbar-item dialog-tool-separator"></span>
			</shiro:hasPermission>
			<shiro:hasPermission name="lcs:marketTemplate:modify">
				<a href="#" class="easyui-linkbutton" plain="true"
					iconCls="icon-remove" onclick="del()">删除</a>
				<span class="toolbar-item dialog-tool-separator"></span>
			</shiro:hasPermission>
			<shiro:hasPermission name="lcs:marketTemplate:update">
				<a href="#" class="easyui-linkbutton" plain="true"
					iconCls="icon-edit" onclick="upd()">修改</a>
				<span class="toolbar-item dialog-tool-separator"></span>
			</shiro:hasPermission>
			<a href="#" class="easyui-linkbutton" plain="true"
					iconCls="icon-hamburg-credit-card" onclick="detail()">预览</a>
			<span class="toolbar-item dialog-tool-separator"></span>
			<shiro:hasPermission name="lcs:marketTemplate:publish">
				<a href="#" class="easyui-linkbutton" plain="true"
					iconCls="icon-hamburg-product" onclick="publish()">发布</a>
			</shiro:hasPermission>
		</div>
	</div>
	<table id="dg"></table>

	<div id="dlg"></div>
	<div id="icon_dlg"></div>
	<div id="editor_dlg"></div>
	<script type="text/javascript">
		var dg;
		var d;
		var permissionDg;
		var parentPermId;
		$(function() {
			dg = $('#dg')
					.datagrid(
							{
								method : "get",
								url : '${ctx}/marketTemp/getAll',
								queryParams:{
						    		sort: 'orderNum', 
						    		order: 'asc'
						    		},
								fit : true,
								fitColumns : true,
								border : false,
								idField : 'id',
								striped : true,
								pagination : true,
								rownumbers : true,
								pageNumber : 1,
								pageSize : 20,
								pageList : [ 10, 20, 30, 40, 50 ],
								singleSelect : true,
								columns : [ [
										{
											field : 'id',
											title : 'id',
											hidden : true,
											width : 100
										},
										{
											field : 'imgurl',
											title : '模板大图',
											align : 'center',
											sortable:false,
											formatter : function(value,
													rowData, rowIndex) {
												var tem = '<img width="190" height="60" src="'+value+'" />';
												if (value == null
														|| value == '')
													tem = '';
												return tem;
											},
											width : 60
										},{
											field : 'simgurl',
											title : '模板小图',
											align : 'center',
											sortable:false,
											formatter : function(value,
													rowData, rowIndex) {
												var tem = '<img width="80" height="60" src="'+value+'" />';
												if (value == null
														|| value == '')
													tem = '';
												return tem;
											},
											width : 30
										},
										{
											field : 'tempname',
											title : '模板名称',
											sortable:false,
											align : 'center',
											width : 30
										},
										{
											field : 'temptype',
											title : '模板类型',
											sortable:false,
											width : 50,
											align : 'center',
											hidden : true
										},
										{
											field : 'tempurl',
											title : '模板地址',
											sortable:false,
											align : 'center',
											width : 80
										},
										{
											field : 'status',
											title : '模板状态',
											sortable:false,
											width : 20,
											align : 'center',
											sortable : false,
											formatter : function(value,
													rowData, rowIndex) {
												if (value == '1') {
													return "<span style='color: red;'>禁用</span>";
												} else if(value == '0') {
													return "<span style='color: green;'>可用</span>";
												}else{
													return "<span style='color: red;'>未知</span>";
												}
											}
										},
										{
											field : 'publishstatus',
											title : '发布状态',
											width : 20,
											align : 'center',
											sortable : false,
											formatter : function(value,
													rowData, rowIndex) {
												if (value == '1') {
													return "<span style='color:green ;'>已发布</span>";
												} else if(value == '0') {
													return "<span style='color: red;'>未发布</span>";
												}else{
													return "<span style='color: red;'>未知</span>";
												}
											}
										},
										{
											field : 'recordtime',
											title : '创建时间',
											align : 'center',
											formatter : function(value, row,
													index) {
												return formatTime(value);
											},
											width : 40
										} ] ],
								enableHeaderClickMenu : false,
								enableHeaderContextMenu : false,
								enableRowContextMenu : false,
								toolbar : '#tb'
							});

		});

		//弹窗增加
		function add() {

			d = $('#dlg').dialog({
				title : '添加模板',
				width : 500,
				height : 270,
				closed : false,
				cache : false,
				maximizable : true,
				resizable : true,
				href : '${ctx}/marketTemp/create',
				modal : true,
				buttons : [ {
					text : '确认',
					handler : function() {
						$("#mainform").submit();
					//	dg.datagrid('reload');
					}
				}, {
					text : '取消',
					handler : function() {
						d.panel('close');
					}
				} ]
			});
		}

		//删除
		function del() {
			var row = dg.datagrid('getSelected');
			if (rowIsNull(row))
				return;
			parent.$.messager.confirm('提示', '删除后无法恢复您确定要删除？', function(data) {
				if (data) {
					$.ajax({
						type : 'get',
						url : "${ctx}/marketTemp/modify/" + row.id,
						success : function(data) {
							if (successTip(data, dg))
								dg.datagrid('reload');
						}
					});
					//dg.datagrid('reload'); //grid移除一行,不需要再刷新
				}
			});

		}
		//删除
		function publish() {
			var row = dg.datagrid('getSelected');
			if (rowIsNull(row))
				return;
			if(row.publishstatus == '1') {
				parent.$.messager.alert('该模板已发布！');
				return;
			}
			parent.$.messager.confirm('提示', '确认要发布该模板么？', function(data) {
				if (data) {
					$.ajax({
						type : 'get',
						url : "${ctx}/marketTemp/publish/" + row.id,
						success : function(data) {
							if (successTip(data, dg))
								dg.datagrid('reload');
						}
					});
					//dg.datagrid('reload'); //grid移除一行,不需要再刷新
				}
			});

		}
		//修改
		function upd() {
			var row = dg.datagrid('getSelected');
			if (rowIsNull(row))
				return;
			d = $("#dlg").dialog({
				title : '修改模板',
				width : 500,
				height : 270,
				href : '${ctx}/marketTemp/update/' + row.id,
				maximizable : true,
				modal : true,
				buttons : [ {
					text : '确认',
					handler : function() {
						$("#mainform").submit();
					}
				}, {
					text : '取消',
					handler : function() {
						d.panel('close');
					}
				} ]
			});

		}
		//模板预览
		function detail(){
			var row = dg.datagrid('getSelected');
			if(rowIsNull(row)) return;
			
			var url = row.tempurl;
			window.open(url,"","width=320,height=680,toolbar=no,scrollbars=yes,menubar=no,screenX=100,screenY=100");
		}
		//创建查询对象并查询
		function cx() {
			var obj = $("#searchFrom").serializeObject();
			obj.filter_LIKES_tempname = encodeURIComponent(obj.filter_LIKES_tempname);
			dg.datagrid('reload', obj);
		}
		var nowIcon;
		var icon_dlg;
	</script>
</body>

</html>